/******************************************************************/
/*                    DoFile Replication file
	Review of Economics and Statistics
	
		Victim incentives and criminal activity: 
		Evidence from bus driver robberies in Chile   		  
			
			Author: Patricio Domínguez
			September, 2020										  */

/******************************************************************/

/* Notes: This dofile generates Tables 6 and 7, and Figure 8 */

set scheme plotplain

/******************************************************************/
/*                    Set directory structure          		      */ 
/******************************************************************/


global rep "/Users/patriciodominguez/RES_Dominguez Dropbox/Patricio Dominguez/Replication/TS"

use "$rep/dta/weapon_si.dta", clear

su
* defining month-year variable [1,72]
g m=month if year==2005
replace m = month+12 if year==2006
replace m = month+12*2 if year==2007
replace m = month+12*3 if year==2008
replace m = month+12*4 if year==2009
replace m = month+12*5 if year==2010

bys m cash: egen total=total(crime)
g prop_f=crime/total if weapon==1
g prop_k=crime/total if weapon==2

g pre=0
replace pre=1 if m<=10
g transition =0
replace transition=1 if m>10 & m<26
g post=0
replace post=1 if m>=26
g period=0 if pre
replace period=1 if transition
replace period=2 if post
table period, c(mean prop_f semean prop_f)
table period, c(mean prop_k semean prop_k)
table period if year<=2008, c(mean prop_f semean prop_f)
table period if year<=2008, c(mean prop_k semean prop_k)
g crime_aux = crime/10 if period==0
replace crime_aux = crime/15 if period==1
replace crime_aux = crime/47 if period==2

bys period cash weapon: egen tot_inj = total(si)
bys period cash weapon: egen tot_c = total(crime)
g prop_injury= tot_inj/tot_c

table weapon period if cash==1, c(sum si sum crime)

est drop _all
reg prop_f transition post if cash==1 & weapon==1, r
eststo e1
reg prop_f transition post i.month if cash==1 & weapon==1, r
eststo e2
reg prop_f transition post if year<=2008 & cash==1 & weapon==1, r
eststo e3
reg prop_f transition post i.month if year<=2008 & cash==1 & weapon==1, r
eststo e4

** Table 6
esttab e*, keep(transition post) se r2  
su prop_f if pre & cash

** Table 7
table weapon period if cash==1, c(mean prop_injury sum crime_aux)  format(%9.2fc)
table period if cash==1, c(sum crime_aux)  format(%9.0fc)

** Figure 8
twoway (line crime m if weapon==1 & cash==1, sort lc(gs8) lp(dash)) ///
		(line crime m if weapon==2 & cash==1, sort lc(gs0) lp(solid)) ///
		(line crime m if weapon==3 & cash==1, sort lc(gs6) lp(dot) xline(10 26, lc(gs4) lp(dash))), ///
		ytitle("# Incidents", size(med)) xtitle("") legend(order(1 "Firearm" 2 "Knife" 3 "Stick")) ///
		tlabel(1 "2005" 13 "2006" 25 "2007" 37 "2008" 49 "2009" 61 "2010" 72 "2011", labsize(med) nogrid) xscale(range(1 72) )
		graph export "$rep/Figures/weapon_evol.pdf", replace


